/*
  Programa Wifis, 2010-2011
  Autor: Nilhcraiv

This file is part of Wifis.

    Wifis is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Wifis is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Wifis.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <QProcess>
#include <QDebug>

#include "linuxos.h"

linuxos::linuxos(QObject *parent)
    : QThread(parent)
{
}

linuxos::~linuxos()
{

}

//Protected functions

void linuxos::run()
{
    //Codigo...
}

//Private functions

QVector <QString> linuxos::searchNetworksInterfaces()
{
    //Variables
    QProcess detectProcess;
    QByteArray textNetworksInterfaces;
    QVector <QString> vectorNetworksInterfaces(0);
    QString tempInterfaces;

    //first I use the command of the GNU/Linux system for to detection neetworks interfaces
    detectProcess.start("/bin/sh -c \"ifconfig -s\"",QIODevice::ReadWrite);

    if (detectProcess.waitForStarted() == false) {
        qDebug() << "Error to detect neetworks";

        vectorNetworksInterfaces.clear();
        return vectorNetworksInterfaces;
    }//if


    detectProcess.waitForReadyRead();
    textNetworksInterfaces = detectProcess.readAllStandardOutput();
    detectProcess.close();

    for(int i=0;i<textNetworksInterfaces.size()-1;i++)
    {
        tempInterfaces.clear();
        while(textNetworksInterfaces.at(i)!='\n')
        {
            i++;
        }i++;//para eliminar el caracter \n
        while(textNetworksInterfaces.at(i)!=' ')
        {
            tempInterfaces.append(textNetworksInterfaces.at(i));
            i++;
            if(i>textNetworksInterfaces.size()-1)
            {
                break;
            }
        }
        vectorNetworksInterfaces.push_back(tempInterfaces);

    }//for devuelve las interfaces en el vector, mas una casilla con un espacio.

    return vectorNetworksInterfaces;
}//searchNetworksInterfaces

/*QVector <QString> linuxos::searchNetworks(QString interface)
{
    //Variables
    QProcess detectProcess;
    QByteArray textNetworks;
    QVector <QString> vectorNetworks;//first ssid, second ...
    QString tempSSID,tempTypeNetwork,tempAutnetwork,tempEncryption,
            tempBSSID,tempSignal,tempRadio,tempChannel,comando("/bin/sh -c \"iwlist ");

    comando.append(interface).append(" scan");

    //first I use the command of the GNU/Linux system for to detection neetworks
    detectProcess.start(comando,QIODevice::ReadWrite);

    if (detectProcess.waitForStarted() == false) {
        qDebug() << "Error to detect neetworks";

        vectorNetworks.clear();
        return vectorNetworks;
    }//if

    detectProcess.waitForReadyRead();
    textNetworks = detectProcess.readAllStandardOutput();
    detectProcess.close();

    //read networks command



}//searchNetworks*/
